using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Ann;

namespace Ann.ExPlatform
{
  public partial class MainForm : Form
  {
    #region Fields
    protected AnnEngine engine = null;
    #endregion
    #region Constructors
    public MainForm()
    {
      InitializeComponent();
      if (this.components == null)
      {
        this.components = new Container();
      }

      if ((this.engine = AnnEngine.it()) != null)
      {
        this.components.Add(engine);
      }
    }
    #endregion
    #region Event Handlers
    private void StartButton_Click(object sender, EventArgs e)
    {
      if (engine.IsProcessing)
      {
        if (engine.Terminate())
        {
          this.StartButton.Text = "&Start";
        }
      }
      else
      {
        if (engine.Start())
        {
          this.StartButton.Text = "&Terminate";
        }
      }
    }

    private void PauseButton_Click(object sender, EventArgs e)
    {
      if (engine.IsSuspending)
      {
        if (engine.Resume())
        {
          this.PauseButton.Text = "&Suspend";
        }
      }
      else
      {
        if (engine.Suspand())
        {
          this.PauseButton.Text = "&Resume";
        }
      }
    }

    private void InjectButton_Click(object sender, EventArgs e)
    {
      using (AnnNeuron.AnnReader reader = AnnNeuron.readerOf(this.engine.Brain.LeftRoot))
      {
        for (int i = 0; i < 10; i++)
        {
          while (reader.IsReading)
          {
            Application.DoEvents();
          }
          if (reader.Read(' '))
          {
            //reading space = 64 (1 bit)
          }
        }
      }
    }
    #endregion
  }
}